package com.yykj.user.center.server.controller.patient;

import com.yykj.common.vo.ResultVO;
import com.yykj.user.center.server.dto.AddressDTO;
import com.yykj.user.center.server.form.AddressForm;
import com.yykj.user.center.server.form.DeleteAddressForm;
import com.yykj.user.center.server.form.UpdateAddressForm;
import com.yykj.user.center.server.service.patient.AddressService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * @author chenl
 * @version 1.0
 * @date 2021/11/5 21:06
 */
@Slf4j
@Api(tags = "地址相关接口")
@RestController
@RequestMapping("/api/address")
@SuppressWarnings("unchecked")
public class AddressController {

    @Autowired
    private AddressService addressService;

    @GetMapping("/info")
    @ApiOperation(value = "地址详情",notes = "地址详情")
    public ResultVO<AddressDTO> info(@RequestParam(value = "id",required = true) String id){
        return ResultVO.success(addressService.info(id));
    }

    @PostMapping("/update")
    @ApiOperation(value = "更新地址",notes = "更新地址")
    public ResultVO update(@Valid @RequestBody UpdateAddressForm updateAddressForm){
        return ResultVO.success(addressService.update(updateAddressForm));
    }

    @PostMapping("/insert")
    @ApiOperation(value = "新增地址",notes = "新增地址")
    public ResultVO insert(@Valid @RequestBody AddressForm addressForm){
        return ResultVO.success(addressService.insert(addressForm));
    }

    @GetMapping("/list")
    @ApiOperation(value = "地址列表",notes = "地址列表")
    public ResultVO list(@RequestParam(value = "patientCardId",required = false) String patientCardId){
        return ResultVO.success(addressService.list(patientCardId));
    }

    @PostMapping("/delete")
    @ApiOperation(value = "地址删除",notes = "地址删除")
    public ResultVO delete(@Valid @RequestBody DeleteAddressForm deleteAddressForm){
        return ResultVO.success(addressService.delete(deleteAddressForm));
    }
}
